var $ = require("jquery");
var Backbone = require("backbone");
var Mask = require("mask");
var util = require("imutil");
var tpl = require("../tpl");
var i18n = require("../i18n");
var servant = require("../i18n/servant");
var config = require("../webim.config");

var defaults = {
	el: null,
	tmpl: tpl.kickout,
	
	urlResetPwd: config.micResetPwd
};

/**
 * 被踢下线界面
 */
var Kickout = function(config){
	this.setConfig(config);
	this.__init();
};

Kickout.prototype = {
	constructor: Kickout,
	
	_: {},
	elems: {},
	setConfig: function(config){
		this.config = util.extend(true, {}, defaults, this.config, config);
	},
	__init: function(){
		this.elems.$el = $(this.config.el);
		this.elems.$content = $(this.config.tmpl(servant.fuse({urlResetPassword: this.config.urlResetPwd}, i18n.kickout)));
		this.elems.$relogin = this.elems.$content.find('.J-im-kickout-relogin')
	},
	__initEvents: function(){
		var _this = this;
		this.elems.$relogin.unbind('click').click(function(e){
			e.preventDefault();
			_this.trigger("relogin");
		});
	},
	show: function(){
		var _this = this;
		
		this.mask = new Mask({
			el: this.elems.$el,
			className: {
				show: 'im-anim-fadeIn-fff',
				hide: ''
			},
			clickToHide: false,
			autoShow: true,
			content: this.elems.$content
		});
		
		this.mask.ready(function(){
			_this.__initEvents();
			_this.trigger('show');
		});
	},
	hide: function(){
		this.mask && this.mask.dispose();
		this.trigger('hide');
	}
};


util.extend(Kickout.prototype, Backbone.Events);

module.exports = Kickout;